package de.tabuma.soapforms.soapproject.view;

import de.tabuma.lib.tabumaview;
import de.tabuma.soapforms.*;
import de.tabuma.soapforms.soapproject.entity.*;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author alefen
 */
public class list extends tabumaview {

    public list(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        String soapProjectName = "name";
        String soapProjectUrl = "url";
        String soapProjectMethod = "method";
        String remove = "remove";
        String noEntry = "no entry";
        String add = "add";
        String projectcall = "->call it";

        out.println("<table class=\"contenttable\">");
        out.println("<tr>");
        out.println("<th class=\"contentth\">"+soapProjectName+"</th>");
        out.println("<th class=\"contentth\">"+soapProjectUrl+"</th>");
        out.println("<th class=\"contentth\">"+soapProjectMethod+"</th>");
        out.println("<th class=\"contentth\"></th>");
        out.println("</tr>");

        List<SoapProject> spList = (List<SoapProject>) request.getAttribute(constants.soapProjectList);

        for(int i=0;i<spList.size();i++) {
            SoapProject sp = spList.get(i);

            String removeLink = this.getServlet() + "?" + this.getLinkAsAttribute() + "&amp;" + constants.soapProjectId + "=" + sp.getId() + "&amp;" + constants.removeSoapProject+"=true";
            String updateLink = this.getServlet() + "?" + this.getLinkAsAttribute() + "&amp;" + constants.soapProjectId + "=" + sp.getId() + "&amp;" + constants.updateSoapProject+"=true";

            out.println("<tr>");
            out.println("<td class=\"contenttd\"><a href=\""+updateLink+"\">"+sp.getName()+"</a><br/><a href=\"soapform?"+constants.soapProjectId+"="+sp.getId().intValue()+"\" target=\"_parent\">"+projectcall+"</a></td>");
            out.println("<td class=\"contenttd\"><a href=\""+updateLink+"\">"+sp.getWsdlUrl()+"</a></td>");
            out.println("<td class=\"contenttd\"><a href=\""+updateLink+"\">"+sp.getMethod()+"</a></td>");
            out.println("<td class=\"contenttd\"><a href=\""+removeLink+"\">"+remove+"</a></td>");
            out.println("</tr>");

        }

        if(spList.size()==0) {
            out.println("<tr>");
            out.println("<td class=\"contenttd\" colspan=\"3\">"+noEntry+"</td>");
            out.println("</tr>");
        }
        out.println("</table>");

        out.println(this.getFormBeginn(null));
        out.println(this.getHiddenAsAttribute());
        out.println("<input type=\"hidden\" name=\""+constants.addSoapProject+"\" value=\"true\"/>");
        out.println("<input type=\"submit\" name=\"add\" value=\""+add+"\" class=\"button\"/>");
        out.println(this.getFormEnd());
        
    }
}
